<?php 
	class WS_GlobalMod {
		
		private $_DB;
		
		public function __construct() {

			$this->_DB 	= new ConfigDB();

		}
		
		public function getPageAccess($strAccess, $strPage) {

			$strAccess  = escapestring($strAccess);
			$strPage 	= escapestring($strPage);

			return $this->_DB->selectDB2("SELECT `access_code`, `access_desc`, `directory`, `php_file`  FROM `tbl_access` WHERE `access_desc` = '" . $strPage . "' AND `access_code` = '" . $strAccess . "'");

		}
		
		public function getPictureName($strID) {

			$strID = escapestring($strID);

			$return =  $this->_DB->selectDB2("SELECT ua.`picture`,
													  CONCAT(ua.`first_name`, ' ', ua.`last_name`) as `name`,
													  ua.`account_no`,
													  ua.`account_type`,
													  ua.`dept_idFK`,
													  d.`dept_desc`
											FROM 	`tbl_users_account` ua
											LEFT JOIN `tbl_department` d ON d.`dept_idPK` = ua.`dept_idFK`
											WHERE 	`user_idPK` = '" . $strID . "'");

			return $return;

		}
		
		public function getStudentPictureName($strID) {

			$strID = escapestring($strID);

			$return =  $this->_DB->selectDB2("SELECT DISTINCT s.`picture`,
															  CONCAT(s.`first_name`, ' ', s.`last_name`) AS `name`,
															  s.`stud_no`,
															  c.`course_idPK`,
															  c.`course_code`,
															  c.`course_desc`,
															  c.`dept_idFK`
															FROM `tbl_students` s
															  INNER JOIN `tbl_courses` c
																ON (s.`course_idFK` = c.`course_idPK`)
															WHERE s.`stud_idPK` = '" . $strID . "' AND s.`is_deleted` = 'N'
													  		LIMIT 1");

			return $return;

		}
		
		public function getStudentSection($strID, $strSemLinkerID, $strYearID) {

			$strID 			= escapestring($strID);
			$strSemLinkerID = escapestring($strSemLinkerID);
			$strYearID 		= escapestring($strYearID);

			$return =  $this->_DB->selectDB2("SELECT DISTINCT sec.`section_idPK`,
															  sec.`section_desc`,
															  ssem.`stud_sem_idPK`
															FROM `tbl_stud_sem` ssem
															  INNER JOIN `tbl_stud_sec` ssec
																ON (ssec.`stud_sem_idFK` = ssem.`stud_sem_idPK`)
															  INNER JOIN `tbl_section` sec
																ON (ssec.`section_idFK` = sec.`section_idPK`)
															WHERE ssem.`stud_idFK` = '" . $strID . "'
															 AND  ssem.`year_idFK` = '" . $strYearID . "'
															 AND  ssem.`sem_linker_idFK` = '" . $strSemLinkerID . "'
															ORDER BY ssec.`stud_sec_idPK` DESC
															LIMIT 1");

			return $return;

		}
		
		public function getActiveYear($strFromYear, $strToYear) {

			$strFromYear = escapestring($strFromYear);
			$strToYear   = escapestring($strToYear);

			return  $this->_DB->selectDB2("SELECT `year_idPK`, `year_from`, `year_to`, `is_summer` FROM `tbl_year` WHERE `is_deleted` = 'N' AND `year_from` = '" . $strFromYear . "' AND `year_to` = '" . $strToYear . "' LIMIT 1");

		}
		
		public function getActiveYearSemester() {

			return  $this->_DB->selectDB2("SELECT `year_idPK`, `year_from`, `year_to`, `is_summer` FROM `tbl_year` WHERE `is_deleted` = 'N'");

		}
		
		public function getActiveYearIfEmty() {

			return  $this->_DB->selectDB2("SELECT COUNT(*) AS `count` FROM `tbl_year` WHERE `is_deleted` = 'N'");

		}
		
		public function insertActiveYear($strFromYear, $strToYear, $strAction = 'N') {

			$strFromYear = escapestring($strFromYear);
			$strToYear   = escapestring($strToYear);
			$strAction   = escapestring($strAction);

			$this->_DB->queryDB("UPDATE `tbl_section` SET `is_deleted` = 'Y'");
			$this->_DB->queryDB("UPDATE `tbl_year` SET `is_deleted` = 'Y'");
			$this->_DB->queryDB("INSERT INTO `tbl_year` (`year_from`, `year_to`, `is_summer`) VALUES ('" . $strFromYear . "', '" . $strToYear . "', '" . $strAction . "')");

		}
		
		public function bible($post) {

			$bookId = escapestring($post['bookId']);
			$bookName = escapestring($post['bookName']);
			$chapter = escapestring($post['chapter']);
			$verse = escapestring($post['verse']);
			$content = escapestring($post['content']);
			
			$this->_DB->queryDB("INSERT INTO `books` (`bookId`, `bookName`, `chapter`, `verse`, `content`) VALUES ('" . $bookId . "', '" . $bookName . "', '" . $chapter . "', '" . $verse . "', '" . $content . "')");

		}
		
	}
?>